package com.orde.service.controler;

import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * FileName: LeaveApprovalController.java
 * Author:   徐寿春
 * Date:     2025/1/8 23:05
 * <p>
 * 名称:
 */
@RestController
public class LeaveApprovalController {

    @Autowired
    private TaskService taskService;

    @PostMapping("/approveLeave")
    public ResponseEntity<String> approveLeave(@RequestParam("taskId") String taskId) {
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        if (task!= null) {
            taskService.complete(task.getId());
            return new ResponseEntity<>("Leave request approved.", HttpStatus.OK);
        } else {
            return new ResponseEntity<>("Task not found.", HttpStatus.BAD_REQUEST);
        }
    }
}
